#include<iostream>
#include<windows.h>
#include<cstring>
using namespace std;

int a[35][35];
bool flag = false;

void Round1() {
	int x, y;
	cin >> x >> y;
	a[y][x] = 1;
	system("cls");
	cout << x << " " << y << endl; 
	for(int i=1; i<=30; i++) {
		for(int j=1; j<=30; j++) {
			if(!a[i][j])	cout << ". ";
			else if(a[i][j] == 1)	cout << "x ";
			else	cout << "o ";
		}
		if(i < 10)	cout << "0" << i << endl;
		else	cout << i << endl;
	}
	cout << 1 << "       " << 5 << "         " << 10 << "        " << 15 << "        " << 20 << "        " << 25 << "        " << 30 << endl;
	for(int i=1; i<=30; i++) {
		for(int j=1; j<=30; j++) {
			if(a[i][j] == 1) {
				if(a[i][j] == a[i][j+1] && a[i][j] == a[i][j+2] && a[i][j] == a[i][j+3] && a[i][j] == a[i][j+4]) {
					flag = true;
					cout << "\"x\" wins!" << endl;
				} else if(a[i][j] == a[i+1][j] && a[i][j] == a[i+2][j] && a[i][j] == a[i+3][j] && a[i][j] == a[i+4][j]) {
					flag = true;
					cout << "\"x\" wins!" << endl;
				} else if(a[i][j] == a[i+1][j+1] && a[i][j] == a[i+2][j+2] && a[i][j] == a[i+3][j+3] && a[i][j] == a[i+4][j+4]) {
					flag = true;
					cout << "\"x\" wins!" << endl;
				} else if(a[i][j] == a[i+1][j-1] && a[i][j] == a[i+2][j-2] && a[i][j] == a[i+3][j-3] && a[i][j] == a[i+4][j-4]) {
					flag = true;
					cout << "\"x\" wins!" << endl;
				}
			}
		}
	}
	return;
}

void Round2() {
	int o, p;
	cin >> o >> p;
	a[p][o] = 2;
	system("cls");
	cout << o << " " << p << endl;
	for(int i=1; i<=30; i++) {
		for(int j=1; j<=30; j++) {
			if(!a[i][j])	cout << ". ";
			else if(a[i][j] == 2)	cout << "o ";
			else	cout << "x ";
		}
		if(i < 10)	cout << "0" << i << endl;
		else	cout << i << endl;
	}
	cout << 1 << "       " << 5 << "         " << 10 << "        " << 15 << "        " << 20 << "        " << 25 << "        " << 30 << endl;
	for(int i=1; i<=30; i++) {
		for(int j=1; j<=30; j++) {
			if(a[i][j] == 2) {
				if(a[i][j] == a[i][j+1] && a[i][j] == a[i][j+2] && a[i][j] == a[i][j+3] && a[i][j] == a[i][j+4]) {
					flag = true;
					cout << "\"o\" wins!" << endl;
				} else if(a[i][j] == a[i+1][j] && a[i][j] == a[i+2][j] && a[i][j] == a[i+3][j] && a[i][j] == a[i+4][j]) {
					flag = true;
					cout << "\"o\" wins!" << endl;
				} else if(a[i][j] == a[i+1][j+1] && a[i][j] == a[i+2][j+2] && a[i][j] == a[i+3][j+3] && a[i][j] == a[i+4][j+4]) {
					flag = true;
					cout << "\"o\" wins!" << endl;
				} else if(a[i][j] == a[i+1][j-1] && a[i][j] == a[i+2][j-2] && a[i][j] == a[i+3][j-3] && a[i][j] == a[i+4][j-4]) {
					flag = true;
					cout << "\"o\" wins!" << endl;
				}
			}
		}
	}
	return;
}

int main() {
	system("title Five-in-a-row");
	system("color F0");
	memset(a, 0, sizeof(a));
	for(int i=1; i<=30; i++) {
		for(int j=1; j<=30; j++) {
			cout << ". ";
		}
		if(i < 10)	cout << "0" << i << endl;
		else	cout << i << endl;
	}
	cout << 1 << "       " << 5 << "         " << 10 << "        " << 15 << "        " << 20 << "        " << 25 << "        " << 30 << endl;
	while(!flag) {
		Round1();
		if(flag == true)	break;
		Round2();
	}
	return 0;
}
